﻿Imports Microsoft.Office.Tools.Ribbon

Public Class Ribbon1

    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load

    End Sub

    Private Sub box_YScale_TextChanged(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles box_YScale.TextChanged
        Dim ans As Double
        If Not Double.TryParse(Me.box_YScale.Text, ans) Then
            Me.box_YScale.Text = 3 / 4
        Else
            Me.box_YScale.Text = ans.ToString()
        End If
    End Sub

    Private Sub button_Preset34_click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles button_Preset34.Click
        Me.box_YScale.Text = (3 / 4).ToString()

    End Sub

    Private Sub button_Preset43_click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles button_Preset43.Click
        Me.box_YScale.Text = (4 / 3).ToString()
    End Sub

    Private Sub button_Go_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles button_Go.Click
        Dim app = Globals.ThisAddIn.Application
        Dim selection = app.ActiveWindow.Selection

        ' Read the Y scale
        Dim scale As Double = Double.Parse(Me.box_YScale.Text)

        If selection.Type = PowerPoint.PpSelectionType.ppSelectionSlides Then
            ' Get the set of slides from the selection
            For Each aSlide In selection.SlideRange
                For Each aShape In aSlide.Shapes
                    reshape_nonplaceholders(aShape, scale)
                Next
            Next
        ElseIf selection.Type = PowerPoint.PpSelectionType.ppSelectionShapes Then
            ' Get the set of shapes from the selection
            For Each aShape In selection.ShapeRange
                reshape_nonplaceholders(aShape, scale)
            Next

        Else
            ' Just get out
            Me.label_Warning.Label = "NO SELECTION !"
            Timer1.Start()
            Timer1.Interval = 200
            Return
        End If

    End Sub

    Sub reshape_nonplaceholders(ByRef aShape As PowerPoint.Shape, ByVal scale As Double)
        If aShape.Type <> Microsoft.Office.Core.MsoShapeType.msoPlaceholder Then
            With aShape
                Dim oldLock = .LockAspectRatio
                .LockAspectRatio = False
                .Height = .Height * scale
                .LockAspectRatio = oldLock
            End With
        End If
    End Sub


    Private Sub button_Fill_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles button_Fill.Click
        AddTestSlides.AddTestSlides()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.label_Warning.Label = "         "
        Timer1.Stop()
    End Sub
End Class
